// pages/category/category.js
let app = getApp();
import {
  list
} from '../../../api/product'

import {
  add,
  buyNow
} from '../../../api/cart'

import {
  productCategoryList
} from '../../../api/productCategory'

const util = require('../../../utils/util.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: 22,
    pageNum: 1,
    pageSize: 20,
    searchBottom: "", //搜索栏底部的位置
    secondBottom: "", //二级导航底部的位置
    firstTop: "", //二级导航的顶部位置
    firstHeight: "", //一级导航的高度
    thirdTop: "", //三级分类的顶部位置
    adSrc: "http://cdn.rzico.com/v4.0/test1.png",
    firstLevelInfo: [],
    showSecondLevel: [],
    productInfoCache: [], //缓存下一页的数据
    isShowSecond: true, //是否显示二级分类
    secondLevelInfo: [],
    thirdLevelInfo: [],
    currentFirstId: "",
    currentSecondId: "",
    currentFirstIndex: "", //目前被选中的一级分类下标
    currentSecondIndex: "", //目前被选中的二级分类下标

    checkNext: false, //用来检查上拉加载是不是要切换到下一个类目
    scrollTop: "", //记录当前滚动的距离
    eInfo: "", //暂存购物车动画的e数据
    firstLevelScrollTop: 0, //一级的纵向滑动位置
    secondLevelScrollLeft: 0, //二级的横向滑动位置
    toIndex: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.info("options--" + JSON.stringify(options))
    let _this = this
    this.getCategoryList(() => {
      // console.info("二级分类的数据secondLevelInfo-*-" + JSON.stringify(this.data.secondLevelInfo))
      if (util.isNull(options.id)) {
        this.data.currentFirstId = this.data.firstLevelInfo[0].id
        this.firstLevelFun(this.data.currentFirstId, true)
      } else {
        let off = true
        if (this.data.firstLevelInfo.length > 0) {
          // console.info("this.data.firstLevelInfo-*-" + JSON.stringify(this.data.firstLevelInfo))
          this.data.firstLevelInfo.map((item, index) => {
            if (item.id == options.id) {
              this.data.currentFirstId = options.id
              off = false
              this.data.currentFirstIndex = index
              this.firstLevelFun(this.data.currentFirstId, true, () => {
                this.getFirstHeight()
              })
            }
          })
        }
        if (off) {
          if (this.data.secondLevelInfo.length > 0) {
            this.data.secondLevelInfo.map(item => {
              if (options.id == item.id) {
                console.info("我被找到了--" + JSON.stringify(item))
                this.data.currentFirstId = item.parentId
                this.data.currentSecondId = item.id
                this.firstLevelFun(this.data.currentFirstId, false, () => {
                  _this.secondLevelFun(this.data.currentSecondId, () => {
                    if (this.data.firstLevelInfo.length > 0) {
                      // console.info("this.data.firstLevelInfo-*-" + JSON.stringify(this.data.firstLevelInfo))
                      this.data.firstLevelInfo.map((item, index) => {
                        if (item.id == this.data.currentFirstId) {
                          this.data.currentFirstIndex = index
                          this.getFirstHeight()
                        }
                      })
                    }
                    if (this.data.showSecondLevel.length > 0) {
                      // console.info("this.data.firstLevelInfo-*-" + JSON.stringify(this.data.firstLevelInfo))
                      this.data.showSecondLevel.map((item, index) => {
                        if (item.id == this.data.currentSecondId) {
                          this.data.currentSecondIndex = index
                          this.getSecondHeight()
                        }
                      })
                    }
                  })
                })
              }
            })
            console.info("我被找到了this.data.currentFirstId--" + this.data.currentFirstId)
          }
        }
      }
    })
    app.event.emit("onCartChange");
  },

  detailsClick(e) {
    // console.info("e--" + JSON.stringify(e.currentTarget.dataset.id))
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/goods/product/details?id=' + id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let statusBarHeight = app.globalData.statusBarHeight
    this.getFirstTop()
    this.setData({
      statusBarHeight: statusBarHeight
    })
  },

  //跳转搜索页
  categorySearch() {
    wx.navigateTo({
      url: '/pages/goods/search/index',
    })
  },

  //获取一级分类的高度
  getFirstHeight(callback) {
    var _this = this;
    let query = wx.createSelectorQuery()
    query.select('.category-firstLevel').boundingClientRect()
    query.select('.category-firstLevel-item').boundingClientRect()
    query.exec((res) => {
      console.info("节点的res--" + JSON.stringify(res))
      let viewHeight = res[0].height
      let itemHeight = res[1].height
      // console.info("itemHeight * (currentFirstIndex+1)--"+itemHeight * (currentFirstIndex+1))
      // console.info("viewHeight--"+viewHeight)
      if (itemHeight * (this.data.currentFirstIndex + 1) >= viewHeight) {
        let scrollDistance = itemHeight * (this.data.currentFirstIndex + 2) - viewHeight
        this.setData({
          firstLevelScrollTop: scrollDistance
        })
      }
    })
  },

  //获取一级分类的宽度
  getSecondHeight(callback) {
    var _this = this;
    let query = wx.createSelectorQuery()
    query.select('.category-secondLevel').boundingClientRect()
    query.select('.category-content-secondLevel-inner').boundingClientRect()
    query.exec((res) => {
      console.info("节点的res--" + JSON.stringify(res))
      let viewWidth = res[0].width
      let itemWidth = res[1].width
      console.info("itemHeight * (this.data.currentSecondIndex+1)--" + itemWidth * (this.data.currentSecondIndex + 1))
      console.info("viewHeight--" + viewWidth)
      if (itemWidth * (this.data.currentSecondIndex + 1) >= viewWidth) {
        let scrollDistance = itemWidth * (this.data.currentSecondIndex + 2) - viewWidth
        this.setData({
          secondLevelScrollLeft: scrollDistance
        })
      }
    })
  },

  //获取顶部的高度
  // firstTop: "", //二级导航的顶部位置
  // thirdTop: "",//三级分类的顶部位置
  getFirstTop() {
    //选择id
    var _this = this;
    let query = wx.createSelectorQuery()
    query.select('.category-search').boundingClientRect()
    query.select('.addCart').boundingClientRect()
    query.select('.category-firstLevel').boundingClientRect()
    query.exec((res) => {
      console.info("节点的res--" + JSON.stringify(res))
      _this.setData({
        firstTop: res[0].bottom,
        firstHeight: res[1].top - res[0].bottom - 10
      })
      console.info("节点的firstHeight--" + this.data.firstHeight)
    })
  },

  //获取分类列表的信息
  getCategoryList(callback) {
    let _this = this
    // console.info("一级分类的数据app.globalData.mchId-*-" + JSON.stringify(app.globalData.mchId))
    productCategoryList({
      mchId: app.globalData.mchId
    }).then(
      res => {
        console.log("商品分类列表res*************************************************")
        console.log(res)
        if (res.type == 'success') {
          _this.formateDateFromFirstAndSecond(res.data)
          if (callback) {
            callback()
          }
        }
      }
    ).catch(error => {
      console.log(error)
    })
  },

  //获取商品列表信息
  getProductrequest(id, isFirst, callback) {
    let _this = this
    console.log("商品信息id--" + JSON.stringify(id))
    let pageSize = _this.data.pageSize
    if (isFirst) { //首次请求多请求一组数据
      pageSize *= 2
      list({
        pageNum: _this.data.pageNum,
        pageSize: pageSize,
        mchId: app.globalData.mchId,
        productCategoryId: id,
        sortField: "product_category_id"
      }).then(
        res => {
          console.log("我是第一次请求的商品信息res--------------------------------")
          console.log(res)
          if (res.type == 'success') {
            if (res.data.data.length > _this.data.pageSize) {
              this.data.productInfoCache = res.data.data.slice(_this.data.pageSize)
            
            } else {
              this.setData({
                showNoMore: true
              })
            }

            console.log("缓存的商品信息res---------------")
            console.log(this.data.productInfoCache)
            if (callback) {
              callback(res.data.data.slice(0, _this.data.pageSize))
              console.log("显示出来的商品信息res---------------")
              console.log(res.data.data.slice(0, _this.data.pageSize))
            }
          }
         
        }
      ).catch(error => {
        console.log(error)
      })
    } else { //后续请求
      list({
        pageNum: _this.data.pageNum,
        pageSize: _this.data.pageSize,
        mchId: app.globalData.mchId,
        productCategoryId: id,
        sortField: "product_category_id"
      }).then(
        res => {
          console.log("我是后续请求的商品信息res--" + JSON.stringify(res))
          if (res.type == 'success') {
            console.log("_this.data.pageNum---------------" + _this.data.pageNum)
            console.log("缓存的商品信息长度---------------" + this.data.productInfoCache.length)
            console.log("请求数据长度---------------" + res.data.data.length)
            if (callback) {
              callback(this.data.productInfoCache)
            }
            if (res.data.data.length > 0) {
              this.data.productInfoCache = res.data.data
            
              // console.log("缓存的商品信息res---------------")
              // console.log(JSON.stringify(this.data.productInfoCache))
            } else {
              this.setData({
                showNoMore: true,
                productInfoCache: []
              })
            }



          }
        }
      ).catch(error => {
        console.log(error)
      })
    }
    
  },

  //整理一级和二级分类数据
  formateDateFromFirstAndSecond(data) {
    if (data.length > 0) {
      let firstLevelInfo = []
      let secondLevelInfo = []
      // //console.info("一二级分类的数据data-*-" + JSON.stringify(data))
      data.map((item) => {
        let firstLevelInfoItem = {}
        firstLevelInfoItem.id = item.id
        firstLevelInfoItem.name = item.name
        firstLevelInfoItem.thumbnail = item.thumbnail
        firstLevelInfoItem.isShow = item.isShow
        firstLevelInfoItem.isSelsected = false
        firstLevelInfo.push(firstLevelInfoItem)
        if (item.childrens.length > 0) {
          item.childrens.map((item1) => {
            let secondLevelInfoItem = {}
            secondLevelInfoItem.parentId = item.id
            secondLevelInfoItem.id = item1.id
            secondLevelInfoItem.name = item1.name
            secondLevelInfoItem.thumbnail = util.thumbnail(item1.thumbnail, 75, 75)
            secondLevelInfoItem.isShow = item1.isShow
            secondLevelInfoItem.isSelsected = false
            secondLevelInfo.push(secondLevelInfoItem)
          })
        }
      })

      // console.info("一级分类的数据firstLevelInfo-*-" + JSON.stringify(firstLevelInfo))
      // console.info("二级分类的数据secondLevelInfo-*-" + JSON.stringify(secondLevelInfo))
      this.setData({
        firstLevelInfo: firstLevelInfo,
        secondLevelInfo: secondLevelInfo
      })
    }
  },

  //整理商品列表数据
  formateDateFromProductList(data, type, callback) {
    //console.info("type--" + type)
    //console.info("开始整理商品数据data--" + JSON.stringify(data))
    let thirdLevelInfoNew = []
    let thirdLevelIdList = []
    if (data.length > 0) {
      data.map((item) => {
        thirdLevelIdList.push(item.productCategoryId)
      })
      thirdLevelIdList = Array.from(new Set(thirdLevelIdList)); //父级id去重
      if (thirdLevelIdList.length > 0) {
        thirdLevelIdList.map((item) => {
          let thirdLevelInfoItem = {}
          thirdLevelInfoItem.productCategoryId = item
          thirdLevelInfoItem.productList = []
          data.map((item1) => {
            if (item == item1.productCategoryId) {
              thirdLevelInfoItem.productCategoryName = item1.productCategoryName
              let productListItem = {}
              productListItem.id = item1.id
              productListItem.marketPrice = item1.marketPrice
              productListItem.name = item1.name
              productListItem.price = item1.price
              productListItem.goodsId = item1.goodsId
              productListItem.thumbnail = util.thumbnail(item1.thumbnail, 232, 232)
              productListItem.stock = item1.stock
              productListItem.sku = item1.sku
              productListItem.point = item1.point
              productListItem.maxLimit = item1.maxLimit
              productListItem.minLimit = item1.minLimit
              productListItem.promotions = item1.promotions
              productListItem.coupons = item1.coupons
              productListItem.subTitle = item1.subTitle
              productListItem.vipPrice = item1.vipPrice
              productListItem.subType = item1.subType
              thirdLevelInfoItem.productList.push(productListItem)
            }
          })
          thirdLevelInfoNew.push(thirdLevelInfoItem)
        })
        // //console.info("thirdLevelInfoNew--" + JSON.stringify(thirdLevelInfoNew))
      }
      let thirdLevelInfo = []
      if (type == "push") {
        thirdLevelInfo = this.data.thirdLevelInfo
        if (thirdLevelInfo.length > 0 && thirdLevelInfoNew.length > 0) {
          let thirdLevelInfoNewIdList = [] //暂存遍历未找到的三级分类
          thirdLevelInfoNew.map((item) => {
            let checkOff = true
            thirdLevelInfo.map((item1) => {
              if (item1.productCategoryId == item.productCategoryId) {
                checkOff = false
                if (item.productList) {
                  item.productList.map((item2) => {
                    item1.productList.push(item2)
                  })
                }
              }
            })
            if (checkOff) {
              thirdLevelInfoNewIdList.push(item.productCategoryId)
            }
          })
          if (thirdLevelInfoNewIdList.length > 0 && thirdLevelInfoNew.length > 0) {
            thirdLevelInfoNewIdList.map((item) => {
              thirdLevelInfoNew.map((item1) => {
                if (item == item1.productCategoryId) {
                  thirdLevelInfo.push(item1)
                }
              })

            })
          }
        }
      } else {
        thirdLevelInfo = thirdLevelInfoNew
      }
      this.setData({
        thirdLevelInfo: thirdLevelInfo
      })
      // console.info("thirdLevelInfo--" + JSON.stringify(this.data.thirdLevelInfo))
    } else {
      this.setData({
        thirdLevelInfo: []
      })
    }
    if (callback) {
      callback()
    }
  },

  //监听页面的滚动事件
  onPageScroll: function(e) {
    // console.log(e.scrollTop);
    this.data.scrollTop = e.scrollTop
    // if (e.scrollTop >= 20) {
    //         if(this.data.pageNum < 2){
    //                 this.data.pageNum = 2
    //         }  
    // } 
    // else {
    //         this.setData({
    //                 isUp: false
    //         })
    // }
  },

  //点击购物车事件
  addProductToCart(e) {
    console.info("e--"+JSON.stringify(e))
    let productId = e.currentTarget.dataset.productinfo.id
    this.data.eInfo = e
    if(e.currentTarget.dataset.productinfo.sku > 1){
      this.selectComponent('#bottomFrame').showFrame(productId, "addCart");
    }else{
      //发送添加购物车的请求
      let data = {}
      data.productId = productId
      data.promotionId = ""
      data.quantity = e.currentTarget.dataset.productinfo.minLimit
      data.uuid = app.globalData.uuid
      console.info("加入购物车的请求data--" + JSON.stringify(data))
      add(data).then(
        res => {
          if (res.type == 'success') {
            wx.showToast({
              title: '成功加入购物车',
              duration: 2000
            })
            this.selectedInfo()
          } 
        }
      ).catch(error => {

      })
    }
    //console.info("e--" + JSON.stringify(e))
    
  },

  //属性选择弹窗完成后数据回传函数
  selectedInfo(data) {
    //console.info("属性数据回收了--" + JSON.stringify(data))
    this.selectComponent('#addCart').touchOnGoods(this.data.eInfo);
  },

  //一级分类的事件
  firstLevelFun(id, needGetProduct, callback) {
    let _this = this
    let isShowSecond = _this.data.isShowSecond
    // console.log("id--" + id);
    let firstLevelInfo = this.data.firstLevelInfo
    let secondLevelInfo = this.data.secondLevelInfo
    let showSecondLevel = []
    if (firstLevelInfo.length > 0) {
      firstLevelInfo.map((item) => {
        if (item.id == id) {
          // if (item.isSelsected == false) {
          item.isSelsected = true
          console.log("开始发送请求");
          //发送请求 
          if (needGetProduct) {
            _this.getProductrequest(id, true, (data) => {
              _this.formateDateFromProductList(data)
              this.data.pageNum = 2
            })
          }
          // else{
          //         _this.getProductrequest(id, false, (data) => {
          //                 _this.formateDateFromProductList(data)
          //         })   
          // }

          // }
        } else {
          item.isSelsected = false
        }
      })
    }

    console.info("secondLevelInfo--" + JSON.stringify(secondLevelInfo))
    let toIndex = ""
    if (secondLevelInfo.length > 0) {
      secondLevelInfo.map((item) => {
        if (item.parentId == id) {
          item.isSelsected = false
          showSecondLevel.push(item)
        }
      })
      console.info("showSecondLevel--" + JSON.stringify(showSecondLevel))
      if (showSecondLevel.length > 0) {
        isShowSecond = true
        toIndex = "secondLevel" + showSecondLevel[0].id
      } else {
        isShowSecond = false
      }
      console.info("isShowSecond--" + JSON.stringify(isShowSecond))

    } else {
      isShowSecond = false
    }
    this.setData({
      toIndex: toIndex,
      isShowSecond: isShowSecond,
      firstLevelInfo: firstLevelInfo,
      showSecondLevel: showSecondLevel,
      // secondClickInfo:secondClickInfo
    })
    if (callback) {
      callback()
    }
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 300
    })
  },

  //一级分类的点击事件
  firstLevelTap(e) {
    this.data.pageNum = 1
    this.data.currentFirstId = e.target.dataset.id
    this.data.currentSecondId = ""
    console.info("一级分类点击的事件pageNum--" + this.data.pageNum)
    this.setData({
      productInfoCache: [],
      thirdLevelInfo: [],
      pageNum: 1,
      showNoMore: false
    })
    this.firstLevelFun(e.target.dataset.id, true)
  },

  //二级分类数据请求事件
  secondLevelFun(id, callback) {
    console.log("id" + JSON.stringify(id));
    let _this = this
    let showSecondLevel = this.data.showSecondLevel
    console.log("showSecondLevel" + JSON.stringify(showSecondLevel));
    if (showSecondLevel.length > 0) {
      showSecondLevel.map((item) => {
        // console.log("item" + JSON.stringify(item));
        if (item.id == id) {
          // if (item.isSelsected == false) {
          item.isSelsected = true
          console.log("开始发送请求");
          _this.getProductrequest(id, true, (data) => {
            _this.formateDateFromProductList(data)
            this.data.pageNum = 2
            if (callback) {
              callback()
            }
          })
          // }

        } else {
          item.isSelsected = false
        }
      })
    }
    this.setData({
      showSecondLevel: showSecondLevel
    })
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 300
    })
  },

  //二级分类点击事件
  secondLevelTap(e) {
    console.info("二级点击事件--" + JSON.stringify(e))
    this.data.currentFirstId = e.currentTarget.dataset.parentid
    this.data.currentSecondId = e.currentTarget.dataset.id
    this.setData({
      productInfoCache: [],
      thirdLevelInfo: [],
      pageNum: 1,
      showNoMore: false
    })
    this.secondLevelFun(e.currentTarget.dataset.id)
  },

  //监听一级分类的滑动你距离
  firstLevelScroll(e) {
    // console.info(e)
    // console.info(e.detail.scrollTop)  
  },

  //监听二级分类的滑动你距离
  secondLevelScroll(e) {
    // console.info(e)
    // console.info(e.detail.scrollLeft)  
  },

  //下拉刷新
  // onPullDownRefresh() {
  //         wx.showNavigationBarLoading();
  //         let showSecondLevel = this.data.showSecondLevel
  //         // //console.info("下拉刷新的时间被触发showSecondLevel--"+JSON.stringify(showSecondLevel))
  //         let selectIndex = ""
  //         if (showSecondLevel.length > 0){
  //                 showSecondLevel.map((item,index)=>{
  //                         if (item.isSelsected){
  //                                 selectIndex = index
  //                         }
  //                 })
  //                 // //console.info("selectIndex--" + selectIndex)
  //                 if (selectIndex == 0) {
  //                         wx.showToast({
  //                                 title: '已经到顶了',
  //                                 icon: "none",
  //                                 duration: 1000,
  //                         })
  //                         wx.stopPullDownRefresh()
  //                 } else {
  //                         selectIndex--
  //                         let id = ""
  //                         showSecondLevel.map((item, index) => {
  //                                 if (index == selectIndex) {
  //                                         id = item.id
  //                                 }
  //                         })
  //                         if (id != ""){
  //                                 this.secondLevelFun(id,()=>{
  //                                         wx.stopPullDownRefresh()   
  //                                 })
  //                         }   
  //                 }
  //         }     
  // },

  //上啦加载
  onReachBottom(e) {
    let _this = this
    //console.info("下拉加载被触发了")
    let showSecondLevel = this.data.showSecondLevel
    //console.info("下拉刷新的时间被触发showSecondLevel--"+JSON.stringify(showSecondLevel))
    let selectIndex = ""
    let id = ""
    let checkNext = this.data.checkNext
    // if(this.data.productInfoCache.length == this.data.pageSize){
    let pageNum = this.data.pageNum
    pageNum++
    this.data.pageNum = pageNum
    if (util.isNull(this.data.currentSecondId)) {
      console.info("我是一级的上拉加载事件-------------------------")
      if (this.data.productInfoCache.length == this.data.pageSize) {
        _this.formateDateFromProductList(this.data.productInfoCache, "push", () => {
          _this.getProductrequest(this.data.currentFirstId, false)
        })
      } else {
        if (this.data.productInfoCache.length > 0) {
          _this.formateDateFromProductList(this.data.productInfoCache, "push")
          this.data.productInfoCache = []
          console.info("我到最后的商品添加了--")
          this.setData({
            showNoMore: true
          })
        } else {
          this.setData({
            showNoMore: true
          })
          let scrollTop = this.data.scrollTop - 40
          console.info("scrollTop--" + scrollTop)
          // wx.pageScrollTo({
          //         scrollTop: scrollTop,
          //         duration: 300
          // })
        }
      }
      // console.info("缓存的数量--"+this.data.productInfoCache.length)
    } else {
      // console.info("我是二级的上拉加载事件-------------------------")
      let currentIndex = ""
      // if (this.data.showSecondLevel.length > 0) {
      //         this.data.showSecondLevel.map((item, index) => {
      //                 if (item.id == this.data.currentSecondId) {
      //                         currentIndex = index
      //                 }
      //         })
      //         if (this.data.pageNum == 2) {
      //                 let showSecondLevel = this.data.showSecondLevel
      //                 showSecondLevel.map(item => {
      //                         if (item.id == this.data.currentSecondId) {
      //                                 item.isSelsected = true
      //                         } else {
      //                                 item.isSelsected = false
      //                         }
      //                 })
      //                 this.setData({
      //                         showSecondLevel: showSecondLevel
      //                 })
      //         }
      // }

      // console.info("缓存的长度--" + this.data.productInfoCache.length)
      if (this.data.productInfoCache.length == this.data.pageSize) {
        _this.formateDateFromProductList(this.data.productInfoCache, "push", () => {
          _this.getProductrequest(this.data.currentSecondId, false)
        })
      } else if (this.data.productInfoCache.length > 0) {
        _this.formateDateFromProductList(this.data.productInfoCache, "push")
        this.data.productInfoCache = []
        // console.info(JSON.stringify(this.data.thirdLevelInfo))
        this.setData({
          showNoMore: true
        })
        let scrollTop = this.data.scrollTop - 40
        // wx.pageScrollTo({
        //         scrollTop: scrollTop,
        //         duration: 300
        // })
        // if(this.data.productInfoCache.length > 0){
        //         if(currentIndex == this.data.showSecondLevel.length-1){
        //                 _this.formateDateFromProductList(this.data.productInfoCache, "push")
        //                 this.data.productInfoCache = []

        //         }else{
        //                 this.data.currentSecondId = this.data.showSecondLevel[currentIndex+1].id
        //                 this.data.pageNum = 1   
        //                 _this.getProductrequest(this.data.currentSecondId, false, (data) => {
        //                         _this.formateDateFromProductList(data, "push")
        //                 })
        //         }

        // }else{
        //         if(currentIndex == this.data.showSecondLevel.length-1){
        //                 wx.showToast({
        //                         title: '没有更多了',
        //                         icon: "none",
        //                         duration: 2000
        //                 })
        //                 let scrollTop = this.data.scrollTop - 40
        //                 wx.pageScrollTo({
        //                         scrollTop: scrollTop,
        //                         duration: 300
        //                 })
        //         }else{
        //                 this.data.currentSecondId = this.data.showSecondLevel[currentIndex+1].id
        //                 this.data.pageNum = 1   
        //                 _this.getProductrequest(this.data.currentSecondId, false, (data) => {
        //                         _this.formateDateFromProductList(data, "push")
        //                 })  
        //         }
        // }
      } else {
        this.setData({
          showNoMore: true
        })
        let scrollTop = this.data.scrollTop - 40
        // wx.pageScrollTo({
        //         scrollTop: scrollTop,
        //         duration: 300
        // })
      }
    }
  },
})